package com.kehao.newcoder;

import org.junit.Test;

import java.util.LinkedHashMap;
import java.util.Map;

public class NC93Solution {
    private LinkedHashMap<Integer,Integer> linkedHashMap = null;

    public NC93Solution(int capacity) {
        // write code here
        linkedHashMap = new LinkedHashMap(capacity,0.75f,true){
            @Override
            protected boolean removeEldestEntry(Map.Entry eldest) {
                return this.size()>capacity;
            }
        };
    }

    public int get(int key) {
        // write code here
        if(linkedHashMap.containsKey(key)){
            return linkedHashMap.get(key);
        }else {
            return -1;
        }
    }

    public void set(int key, int value) {
        // write code here
        linkedHashMap.put(key,value);
    }

    public static void main(String[] args){
        NC93Solution s = new NC93Solution(2);
        int output;
        s.set(1,1);
        s.set(2,2);
        output=s.get(1);
        s.set(3,3);
        output=s.get(2);
    }

}
